<template>
	<view class="content">
		<view class="top">
			<view class="left">
				<view class="alpsoftjurnal">
				{{$t('user.gold1')}}
				<span>{{forever_coin}} <image src="@/static/gold.png"></image></span>
				</view>
				<view class="alpsoftjurnal">
				{{$t('user.gold2')}}
				<span>{{coin_amount}} <image src="@/static/gold.png"></image></span>
				</view>
			</view>
			<view class="right alpsoftjurnal">{{$t('gold.button1')}}</view>
		</view>
		<scroll-view class="scroll-view" scroll-y="true" @scrolltolower="lower">
			<view class="item" v-for="(item, index) in list" :key="index">
				<view class="left">
					<view class="title alpsoftjurnal" v-if="lang == 'wwe'">
						{{ item.uyg_from }}
					</view>
					<view class="title" v-else>
						{{ item.from }}
					</view>
					{{ item.create_time}}
				</view>
				<view class="right">
					{{item.type ==1?'+':'-' }} {{ item.quantity }}<image src="@/static/gold.png"></image>
				</view>
			</view>
		</scroll-view>
	</view>
</template>

<script>
import util from '../../utils/util'
	export default {
		data() {
			return {
				params: {
					page: 1,
					page_size: 10,
				},
				total: 0,
				list: [],
				forever_coin: '',
				coin_amount: '',
				lang: ''
			}
		},
		onLoad() {
			this.coinList()
			this.getUserCoinAmount()
			util.setNavTitle()
			this.lang = uni.getStorageSync('language')
		},
		methods: {
			coinList() {
				let userinfo = uni.getStorageSync('userinfo')
				this.params.token = userinfo.token
				uni.request({
					url: this.configs.webUrl + '/api/user_coin/coinList',
					data: this.params,
					success: res => {
						console.log(res);
						this.list = this.list.concat(res.data.data.list)
						this.total = res.data.data.count
					}
				})
			},
			lower() {
				if(this.total>this.params.page*this.params.page_size) {
					this.params.page++
					this.coinList()
				}
			},
			getUserCoinAmount() {
				uni.request({
					url: this.configs.webUrl + '/api/user_coin/getUserCoinAmount',
					data: {
						token: uni.getStorageSync('userinfo').token
					},
					success: res => {
						console.log(res);
						this.forever_coin = res.data.data.forever_coin
						this.coin_amount = res.data.data.coin_amount
					}
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	view {
		font-size: initial;
	}

	.content {
		padding: 20rpx;

		.top {
			background: linear-gradient(134deg, #EF897B 0%, #AA275D 100%);
			border-radius: 24rpx;
			display: flex;
			align-items: center;
			justify-content: space-between;
			height: 146rpx;
			padding: 0 20rpx;

			.left {
				font-size: 28rpx;
				font-family: PingFang SC, PingFang SC;
				font-weight: 500;
				color: #FFFFFF;

				span {
					margin-left: 20rpx;
					font-size: 40rpx;
					font-family: PingFang SC, PingFang SC;
					font-weight: 600;
					color: #FFFFFF;

					image {
						width: 27rpx;
						height: 27rpx;
						margin-left: 10rpx;
					}
				}
			}

			.right {
				background: #fff;
				padding: 10rpx 20rpx;
				font-size: 24rpx;
				font-family: PingFang SC, PingFang SC;
				font-weight: 400;
				color: #A7215B;
				border-radius: 24rpx;
			}
		}

		.scroll-view {
			height: calc(100vh - 186rpx);

			.item {
				display: flex;
				padding: 20rpx;
				align-items: center;
				background: #fff;
				border-radius: 24rpx;
				margin: 10rpx 0;
				justify-content: space-between;

				.left {
					.title {
						font-size: 28rpx;
						font-family: PingFang SC, PingFang SC;
						font-weight: 500;
						color: #000000;
						margin-bottom: 10rpx;
					}

					font-size: 24rpx;
					font-family: PingFang SC,
					PingFang SC;
					font-weight: 400;
					color: #AAAAAA;
				}

				.right {
					font-size: 40rpx;
					font-family: PingFang SC, PingFang SC;
					font-weight: 600;
					color: #FB9D2F;

					image {
						width: 27rpx;
						height: 27rpx;
						margin-left: 10rpx;
					}
				}
			}
		}
	}
</style>